home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / CDaemon / HACK16 / Sources / ATA Utility.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  7.0 KB  |  205 lines

  1. #ifndef __ATA_DEMO_H__
  2. #define __ATA_DEMO_H__
  3.  
  4. #ifdef __cplusplus
  5.     extern "C" {
  6. #endif
  7.  
  8. //------------------------------------------------------------------------------------
  9. #pragma mark Includes
  10. //------------------------------------------------------------------------------------
  11. #include <TextUtils.h>
  12. #include <Patches.h>
  13. #include <Traps.h>
  14. #include <Devices.h>
  15. #include <ATA.h>
  16.  
  17. //------------------------------------------------------------------------------------
  18. #pragma mark Defines
  19. //------------------------------------------------------------------------------------
  20.  
  21. //
  22. // Identifies the bus protocol type.
  23. //
  24.  
  25. enum {
  26.     kDevUnknown        =    0,
  27.     kDevATA            =    1,
  28.     kDevATAPI        =    2,
  29.     kDevPCMCIA        =    3
  30. };
  31.  
  32. //
  33. // Identifies the Socket type.
  34. //
  35. enum {
  36.     kSocketUnknown        =    0,
  37.     kSocketInternal        =    1,
  38.     kSocketMediaBay        =    2,
  39.     kkSocketPCMCIA        =    3
  40. };
  41.  
  42.  
  43. // .AppleCD contants 
  44. enum
  45.     {
  46.     csSetPowerMode    =    70,
  47.     csQuiescence    =    0x437
  48.     };
  49.  
  50. enum
  51.     {
  52.     pmActive        =    0,
  53.     pmStandby        =    1,
  54.     pmIdle            =    2,
  55.     pmSleep            =    3
  56.     };
  57.  
  58. enum
  59.     {
  60.     quiescenceON    =    0,
  61.     quiescenceOFF    =    1
  62.     };
  63.  
  64.  
  65. //------------------------------------------------------------------------------------
  66. #pragma mark Macros
  67. //------------------------------------------------------------------------------------
  68.  
  69. #define CLEAR(what) do {                        \
  70.         register Ptr        _ptr = (Ptr) &what;    \
  71.         register Size        _len = sizeof what;    \
  72.         for (; _len > 0; --_len)                    \
  73.             *_ptr++ = 0;                        \
  74.     } while (0)
  75.  
  76. #define IF_ERROR(_err_,_str_) if (_err_ != noErr) { printf(_str_); return (_err_); }
  77.  
  78.  
  79. //------------------------------------------------------------------------------------
  80. #pragma mark -
  81.  
  82. //------------------------------------------------------------------------------------
  83. #pragma mark Identify Drive Info
  84. //------------------------------------------------------------------------------------
  85.  
  86. //
  87. //  Bit fields returned from Identify Drive command
  88. //
  89. enum {
  90.     magdrv_bit        =    15,            /* WORD 0: bit number of mag drive indicator    */
  91.     rcd_bit            =    7,            /* WORD 0: bit number of removable indicator    */
  92.     fixed_bit        =    6,            /* WORD 0: bit number of fixed disk indicator    */
  93.  
  94.     lbamode_bit        =    9,            /* bit number of lba support indicator            */
  95.     iordy_bit        =    11,            /* bit number of IORDY support indicator        */
  96.     extvalid_bit    =    1,            /* bit number of valid extension word            */
  97.     mode3_bit        =    0,            /* WORD 64: bit number of mode 3 support        */
  98.     
  99.     kMagDrv            =    1 << magdrv_bit,    /* Bit 15 = 0 -> a magnetic drive        */
  100.     kRemovable        =    1 << rcd_bit,        /* Bit 7 != 0 -> removable cartridge    */
  101.     kFixed            =    1 << fixed_bit,        /* Bit 6 != 0 -> indicates fixed drive    */
  102.     kLBAMode        =    1 << lbamode_bit,    /* LBA support indicator                */
  103.     kIORDY            =    1 << iordy_bit,        /* IORDY support indicator                */
  104.     kExtValid        =    1 << extvalid_bit,    /* Extension word valid                    */
  105.     MODE3BIT        =    1 << mode3_bit        /* mode 3 bit in word 64 of ident data    */
  106. };
  107.  
  108. //
  109. // This is returned by the device in response to an IDENTIFY command (512 bytes).
  110. //
  111. typedef    struct IdentifyBlock {    /* Structure of Identify data                        */
  112.     short    Signature;            /* Word 00: Constant value                            */
  113.     short    NumCyls;            /* Word 01:    Number of cylinders (default mode)            */
  114.     short    RSVD0;                /* Word 02:    Constant value of 0                        */
  115.     short    NumHds;                /* Word 03:    Number of heads (default mode)            */
  116.     short    TrkBytes;            /* Word 04:    Number of unformatted bytes/track        */
  117.     short    SecBytes;            /* Word 05:    Number of unformatted bytes/sector        */
  118.     short    NumSecs;            /* Word 06:    Number of sectors/track                    */
  119.     short    VU0;                /* Word 07:    Vendor unique                            */
  120.     short    VU1;                /* Word 08:    Vendor unique                            */
  121.     short    VU2;                /* Word 09:    Vendor unique                            */
  122.     short    Serial[10];            /* Word 10-19:    Serial Number (right-justified)        */
  123.     short    BufType;            /* Word 20:    Buffer Type                                */
  124.     short    BufSize;            /* Word 21:    Buffer size in 512 byte increments        */
  125.     short    NumECC;                /* Word 22:    Number of ECC bytes                        */
  126.     short    FirmRev[4];            /* Word 23-26:    Firmware revision (left-justified)    */
  127.     short    ModelNum[20];        /* Word 27-46:    Model number (left-justified)        */
  128.     short    MultCmds;            /* Word 47:    R/W multiple commands not impl = 0        */
  129.     short    DblXferFlag;        /* Word 48:    Double transfer flag                    */
  130.     short    Capabilities;        /* Word 49: LBA, DMA, IORDY support indicator        */
  131.     short    Reserved1;            /* Word 50: Reserved                                */
  132.     short    PIOTiming;            /* Word 51: PIO transfer timing mode                */
  133.     short    DMATiming;            /* Word 52:    DMA transfer timing mode                */
  134.     short    Extension;            /* Word 53: extended info support                    */
  135.     short    CurCylinders;        /* Word 54: number of current cylinders                */
  136.     short    CurHeads;            /* Word 55: number of current heads                    */
  137.     short    CurSPT;                /* Word 56: number of current sectors per track        */
  138.     short    CurCapacity[2];        /* Word 57-58: current capacity in sectors            */
  139.     short    MultSectors;        /* Word 59: Multiple sector setting                    */
  140.     short    LBACapacity[2];        /* Word 60-61: total sectors in LBA mode            */
  141.     short    SWDMA;                /* Word 62: single word DMA support                    */
  142.     short    MWDMA;                /* Word 63: multi word DMA support                    */
  143.     short    APIOModes;            /* Word 64:    Advanced PIO Xfr mode supported            */
  144.     short    MDMATiming;            /* Word 65:    Minimum Multiword DMA Xfr Cycle            */
  145.     short    RDMATiming;            /* Word 66:    Recommended Multiword DMA Cycle            */
  146.     short    MPIOTiming;            /* Word 67:    Min PIO XFR Time W/O Flow Control        */
  147.     short    PIOwRDYTiming;        /* Word 68:    Min PIO XFR Time with IORDY flow ctrl    */
  148.     short    Reserved[187];        /* Word 69-255: Reserved                            */
  149. } IdentifyBlock;
  150.  
  151. //
  152. // The following structure and table simplifies the formatting.
  153. //
  154. enum {
  155.     kEndOfTable = 0,            /* Marker                                            */
  156.     kDecimal,                    /* Signed integer (two words are high..low)            */
  157.     kHex,                        /* Bitfield                                            */
  158.     kLeftJust,                    /* Ascii, left-justified, space padded                */
  159.     kRightJust                    /* Ascii, right-justified, space padded                */
  160. };
  161. struct FormatTable {
  162.     short        firstWord;        /* First word in IdentifyBlock cast to short vector    */
  163.     short        lastWord;        /* Last word in IdentifyBlock cast to short vector    */
  164.     short        format;            /* Format from above enum                            */
  165.     const char    *label;            /* Text to display                                    */
  166. };
  167.  
  168. typedef struct FormatTable FormatTable, *FormatTablePtr;
  169.  
  170.  
  171.  
  172. //------------------------------------------------------------------------------------
  173. #pragma mark Prototypes
  174. //------------------------------------------------------------------------------------
  175.  
  176. Boolean     ATAManagerPresent    (void);
  177. Boolean     ATAHardwarePresent    (void);
  178. Boolean     TrapAvailable        (short theTrap);
  179. void         PrintNumVersion        (char *label, NumVersion version );
  180. OSErr         DisplayATAManagerInquiryInfo (void);
  181.  
  182. OSErr         ScanATABusses         (void);
  183. OSErr         DisplayATADriveIdentity (UInt32 deviceID );
  184. void        DumpRawBuffer        ( UInt8 *bufferPtr, int length );
  185. void        DumpFormatedBuffer    (void* p, const  FormatTablePtr formatPtr);
  186. char*        DrvrRefToName        (short refNum);
  187.  
  188. OSErr         DisableCDDriver     (SInt16 refNum);
  189. OSErr         EnableCDDriver         (SInt16 refNum);
  190. OSErr         WakeUpCDDrive         (SInt16 refNum);
  191. OSErr         SetQuiescence         (SInt16 refNum, UInt16 mode);
  192.  
  193. OSErr        ATARead( UInt32 deviceID, UInt8* buffer );
  194. OSErr        ATAPIRead( UInt32 deviceID, UInt8* buffer );
  195.  
  196.  
  197. //------------------------------------------------------------------------------------
  198. #pragma mark -
  199.  
  200. #endif
  201.  
  202. #ifdef __cplusplus
  203.     }
  204. #endif
  205.